﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataLayer;
using ExceptionLayer;

namespace CtrLayer
{
    public class ArtistCtrl
    {
        public void CreateArtist(string name, string address, string cellphone)
        {
            Artist newArtist = new Artist { Name = name, Address = address, Cellphone = cellphone };

            DBCon.GetDB().Artists.InsertOnSubmit(newArtist);
            DBCon.GetDB().SubmitChanges();
        }

        public void DeleteArtist(int id)
        {
            Artist delArtist = (from x in DBCon.GetDB().Artists
                                where x.ID == id
                                select x).Single();

            if (delArtist != null)
            {
                DBCon.GetDB().Artists.DeleteOnSubmit(delArtist);
                DBCon.GetDB().SubmitChanges();
            }
            else
            {
                throw new UCNEmptyException();
            }
        }

        public void UpdateArtist(int id, string name, string address, string cellphone)
        {
            Artist updArtist = (from x in DBCon.GetDB().Artists
                                where x.ID == id
                                select x).Single();

            updArtist.Name = name;
            updArtist.Address = address;
            updArtist.Cellphone = cellphone;

            DBCon.GetDB().SubmitChanges();
        }

        public List<Artist> SearchArtist(int id)
        {
            var query = (from x in DBCon.GetDB().Artists
                         where x.ID == id
                         select x);

            return query.ToList();
        }

    }
}
